package com.rong.ruiji.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rong.ruiji.common.BaseContext;
import com.rong.ruiji.dto.SetmealDto;
import com.rong.ruiji.entity.SetMeal;
import com.rong.ruiji.entity.SetmealDish;
import com.rong.ruiji.mapper.SetMealMapper;
import com.rong.ruiji.service.SetMealService;
import com.rong.ruiji.service.SetmealDishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SetMealServiceImpl extends ServiceImpl<SetMealMapper, SetMeal> implements SetMealService {

    @Autowired
    private SetmealDishService setmealDishService ;

    @Override
    @Transactional
    public void saveWithSetmealDish(Long emd,SetmealDto setmealDto) {
        BaseContext.setCurrentId(emd);
        this.save(setmealDto);
        Long setMealId = setmealDto.getId();
        List<SetmealDish> list = setmealDto.getSetmealDishes();
        for (SetmealDish setmealDish : list) {
            setmealDish.setSetmealId(setMealId);
        }
        setmealDishService.saveBatch(list);
    }
}
